<template>
    <div class="box1">
       <h1>内容</h1>
       <h1>内容</h1>
       <h1>内容</h1>
       <h1>内容</h1>
       <h1>内容</h1>
       <button @click="yes">打开弹出框</button>
       <teleport to="body" v-if="is">
        <div class="box2">
            <div class="box">
                <h1>我是弹出框</h1>
                <button @click="no">关闭弹出框</button>
            </div>
        </div>
       </teleport>
    </div>
</template>
<script>
import { ref } from 'vue';

export default{
    setup(){
        let is = ref(false)
        function yes(){
            is.value = true
        }
        function no(){
            is.value = false
        }
        return {yes,is,no}
    }
}
</script>
<style lang="less">

.box1{
    background-color: blue;
}
.box2{
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background-color: rgba(0,0,0,0.5);
}
.box{
    text-align: center;
    width: 300px;
    height: 200px;
    background-color: aquamarine;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
}
</style>